﻿#ifdef _WIN32
#include "windows_defines.h"
#endif

#include "../../../../../../unittest/framework/unittest.hh"

#include "GuildApplicationInfo_struct.h"
#include "GuildModuleApplication_struct.h"
#include "GuildModuleBrief_struct.h"
#include "GuildMember_struct.h"
#include "GuildModuleMembers_struct.h"

#include "AnnounceData_struct.h"
#include "AnnounceMsg_struct.h"
#include "ApplyJoinGuildArg_struct.h"
#include "ApplyJoinGuildRes_struct.h"
#include "ApproveJoinGuildArg_struct.h"
#include "ApproveJoinGuildRes_struct.h"
#include "ChangeGuildAnnounceArg_struct.h"
#include "ChangeGuildAnnounceRes_struct.h"
#include "ChangeGuildDeclarationArg_struct.h"
#include "ChangeGuildDeclarationRes_struct.h"
#include "ChangeGuildIconIdArg_struct.h"
#include "ChangeGuildIconIdRes_struct.h"
#include "ChangeGuildNameArg_struct.h"
#include "ChangeGuildNameRes_struct.h"
#include "CreateGuildArg_struct.h"
#include "CreateGuildRes_struct.h"
#include "GetGuildApplicationArg_struct.h"
#include "GetGuildApplicationRes_struct.h"
#include "GetGuildBriefArg_struct.h"
#include "GetGuildBriefListArg_struct.h"
#include "GetGuildBriefListRes_struct.h"
#include "GetGuildBriefRes_struct.h"
#include "GetGuildMemberArg_struct.h"
#include "GetGuildMemberRes_struct.h"
#include "GuildServiceBasic/proxy/guildservicebasic.service.GuildServiceBasic.proxy.h"
#include "GuildServiceBasic/stub/guildservicebasic.service.GuildServiceBasic.stub.h"
#include "GuildServiceQuery/proxy/guildservicequery.service.GuildServiceQuery.proxy.h"
#include "GuildServiceQuery/stub/guildservicequery.service.GuildServiceQuery.stub.h"
#include "KickOutGuildMemberArg_struct.h"
#include "KickOutGuildMemberRes_struct.h"
#include "QuitGuildArg_struct.h"
#include "QuitGuildRes_struct.h"
#include "SearchGuildArg_struct.h"
#include "SearchGuildRes_struct.h"
#include "SetAutoApprovalArg_struct.h"
#include "SetAutoApprovalRes_struct.h"
#include "GetGuildMembersArg_struct.h"
#include "GetGuildMembersRes_struct.h"
#include "SetGuildMemberDutyArg_struct.h"
#include "SetGuildMemberDutyRes_struct.h"
#include "RegisterArg_struct.h"
#include "RegisterRes_struct.h"
#include "UnregisterNtfData_struct.h"

#include "guildservicewelfare/LoginArg_struct.h"
#include "guildservicewelfare/LoginRes_struct.h"

#include "box/service_box.hh"
#include "box/service_context.hh"
#include "detail/service_context_impl.hh"

#include "guild_service_basic_context.h"
#include "guild_service_query_context.h"
#include "guild_service_auth_context.h"

#include "protobuf/guildservicebasic.service.pb.h"
#include "protobuf/guildservicequery.service.pb.h"
#include "util/time_util.hh"
#include "guild/guild.h"

FIXTURE_BEGIN(test_guild_service_basic)

std::array<guild_service::role_uuid_type, 10> role_uuid_list;
std::array<guild_service::guild_id_type, 10> guild_id_list;
std::array<guild_service::token_type, 10> token_list;

bool is_auto_approval = true;
uint32_t icon_id = 0;
std::string declaration = "one declaration";
std::string announce = "one announce";
const char* argv[] = {"test_basic", "--config=test_basic_box.cfg"};
kratos::service::ServiceBox* box = new kratos::service::ServiceBox();
uint32_t test_round = 0;

SETUP([&]() {
  std::cout << "\n==================================== "
            << "Round " << test_round++
            << " ====================================\n";
  srand(static_cast<unsigned int>(time(nullptr)));

  role_uuid_list.fill(0ull);

  token_list.fill(0ull);

  guild_id_list.fill(0ull);

  icon_id = rand() % 10 + 1;

  box->start(2, argv);
})

/// 服务开始
#define BOX_SERVICE_START()                                                   \
  auto context_imp_ptr =                                                      \
      kratos::make_unique_pool_ptr<kratos::service::ServiceContextImpl>(box); \
  auto context_ptr =                                                          \
      dynamic_cast<kratos::service::ServiceContext*>(context_imp_ptr.get());  \
  ASSERT_TRUE(guild_service::GuildServiceBasicContext::Init(context_ptr));    \
  ASSERT_TRUE(guild_service::GuildServiceQueryContext::Init(context_ptr));    \
  ASSERT_TRUE(guild_service::GuildServiceAuthContext::Init(context_ptr));

/// 服务等待
#define BOX_SERVICE_WAIT(ms)                                      \
  {                                                               \
    auto start = kratos::util::get_os_time_millionsecond();       \
    while (true) {                                                \
      auto now = kratos::util::get_os_time_millionsecond();       \
      if (now - start > ms) {                                     \
        break;                                                    \
      }                                                           \
      std::this_thread::sleep_for(std::chrono::milliseconds(10)); \
    }                                                             \
  }

/// 服务运行
#define BOX_SERVICE_RUN(ms)                                       \
  {                                                               \
    auto start = kratos::util::get_os_time_millionsecond();       \
    while (true) {                                                \
      guild_service::GuildServiceBasicContext::Tick(              \
          kratos::util::get_os_time_millionsecond());             \
      guild_service::GuildServiceQueryContext::Tick(              \
          kratos::util::get_os_time_millionsecond());             \
      guild_service::GuildServiceAuthContext::Tick(               \
          kratos::util::get_os_time_millionsecond());             \
      auto now = kratos::util::get_os_time_millionsecond();       \
      if (now - start > ms) {                                     \
        break;                                                    \
      }                                                           \
      std::this_thread::sleep_for(std::chrono::milliseconds(10)); \
    }                                                             \
  }

/// 服务停止
#define BOX_SERVICE_STOP(ms)                                        \
  {                                                                 \
    BOX_SERVICE_RUN(ms)                                             \
    ASSERT_TRUE(guild_service::GuildServiceBasicContext::Uninit()); \
    ASSERT_TRUE(guild_service::GuildServiceQueryContext::Uninit()); \
    ASSERT_TRUE(guild_service::GuildServiceAuthContext::Uninit());  \
  }

/// 注册
CASE(TestGuildServiceBasic0) {
  BOX_SERVICE_START()
  co(
    std::cout << '\n'; for (int i = 0; i < 4; ++i) {
    RegisterArg arg;
    arg.account = guild_service::kTestAccountList[i];
    arg.passwd = guild_service::kTestPasswdList[i];
    rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
         std::shared_ptr<rpc::StubCallImpl>(nullptr));

    std::cout << "Register"
              << "\t账号:" << arg.account << "\t密码:" << arg.passwd << '\n';

    auto res = std::make_shared<RegisterRes>();
    try {
      guild_service::GuildServiceAuthContext::Register(call, arg, res);
      {
        std::cout << "Register"
                  << "\t结果:" << static_cast<int>(res->result)
                  << "\t凭证:" << res->token
                  << "\t角色唯一id:" << res->role_uuid << '\n';
      }

      ASSERT_TRUE(res->result == guildserviceauth_cpp::ErrorCode::ERR_SUCCESS);
      ASSERT_TRUE(res->token != 0);
      ASSERT_TRUE(res->role_uuid != 0);

      token_list[i] = res->token;
      role_uuid_list[i] = res->role_uuid;
    } catch (std::exception& ex) {
      std::cerr << "Register exception &:" << ex.what() << std::endl;
    }
  }) BOX_SERVICE_STOP(2000)
}

/// 创建公会
CASE(TestGuildServiceBasic1) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n';

      CreateGuildArg arg; arg.token = token_list[0];
      arg.name = "guild" + std::to_string(arg.token) + ":" +
                 std::to_string(role_uuid_list[0]);
      rpc::StubCallPtr call = std::shared_ptr<rpc::StubCallImpl>(nullptr);

      std::cout << "CreateGuild"
                << "\t凭证:" << arg.token << "\t公会名字:" << arg.name
                << '\n';

      auto res = std::make_shared<CreateGuildRes>();

      try {
        guild_service::GuildServiceBasicContext::CreateGuild(call, arg, res);
        {
          std::cout << "CreateGuild"
                    << "\t结果:" << static_cast<int>(res->result)
                    << "\t公会id:" << res->id << '\n';
        }
        ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
        ASSERT_TRUE(res->id != 0);

        guild_id_list[0] = res->id;
      } catch (std::exception & ex) {
        std::cerr << "CreateGuild exception &:" << ex.what() << std::endl;
      }) BOX_SERVICE_STOP(500)
}

/// 加入公会
CASE(TestGuildServiceBasic2) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n'; {
        for (int i = 1; i <= 2; ++i) {
          ApplyJoinGuildArg arg;
          arg.token = token_list[i];
          arg.guild_id = guild_id_list[0];
          arg.invite_role_uuid = role_uuid_list[0];
          rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
              std::shared_ptr<rpc::StubCallImpl>(nullptr));

          std::cout << "ApplyJoinGuild"
                    << "\t玩家凭证:" << arg.token << "\t公会id:" << arg.guild_id
                    << "\t发起邀请的角色唯一id:" << arg.invite_role_uuid
                    << '\n';

          auto res = std::make_shared<ApplyJoinGuildRes>();
          try {
            guild_service::GuildServiceBasicContext::ApplyJoinGuild(call, arg, res);
            {
              std::cout << "ApplyJoinGuild"
                        << "\t结果:" << static_cast<int32_t>(res->result)
                        << '\n';
            }
            ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
          } catch (std::exception & ex) {
            std::cerr << "ApplyJoinGuild exception &:" << ex.what() << std::endl;
          }
        }
      } {
        SetAutoApprovalArg arg;

        arg.token = token_list[0];
        arg.is_auto_approval = is_auto_approval;
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "SetAutoApproval"
                  << "\t玩家凭证:" << arg.token
                  << "\t是否自动同意入会:" << (arg.is_auto_approval ? 1 : 0)
                  << '\n';

        auto res = std::make_shared<SetAutoApprovalRes>();
        try {
          guild_service::GuildServiceBasicContext::SetAutoApproval(call, arg, res);
          {
            std::cout << "SetAutoApproval"
                      << "\t结果:" << static_cast<int32_t>(res->result) << '\n';
          }
          ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception& ex) {
          std::cerr << "SetAutoApproval exception &:" << ex.what() << std::endl;
        }
      } BOX_SERVICE_WAIT(500) {
        ApplyJoinGuildArg arg;
        arg.token = token_list[3];
        arg.guild_id = guild_id_list[0];
        arg.invite_role_uuid = role_uuid_list[0];
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "ApplyJoinGuild"
                  << "\t凭证:" << arg.token << "\t公会id:" << arg.guild_id
                  << "\t发起邀请的角色唯一id:" << arg.invite_role_uuid << '\n';

        auto res = std::make_shared<ApplyJoinGuildRes>();
        try {
          guild_service::GuildServiceBasicContext::ApplyJoinGuild(call, arg, res);
          {
            std::cout << "ApplyJoinGuild"
                      << "\t结果:" << static_cast<int32_t>(res->result) << '\n';
          }
          ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception & ex) {
          std::cerr << "ApplyJoinGuild exception &:" << ex.what() << std::endl;
        }
      }) BOX_SERVICE_STOP(1500)
}

/// 获取申请入会列表
CASE(TestGuildServiceBasic3) {
  BOX_SERVICE_START()

  std::vector<uint64_t> apply_role_uuid_list;

  co(
      std::cout << '\n'; {
        GetGuildApplicationArg arg;
        arg.token = token_list[0];
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "GetGuildApplication"
                  << "\t玩家凭证:" << arg.token << '\n';

        auto res = std::make_shared<GetGuildApplicationRes>();
        try {
          guild_service::GuildServiceQueryContext::GetGuildApplication(call, arg,
                                                                       res);
          {
            for (const auto& it : res->application.application_list) {
              std::cout << "GetGuildApplication"
                        << "\t结果:" << static_cast<int32_t>(res->result)
                        << "\t申请角色唯一id:" << it.role_uuid
                        << "\t申请角色性别:" << static_cast<int>(it.role_sex)
                        << '\n';
              apply_role_uuid_list.emplace_back(it.role_uuid);
            }
          }
          ASSERT_TRUE(res->result == guildservicequery_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception & ex) {
          std::cerr << "GetGuildApplication exception &:" << ex.what()
                    << std::endl;
        }
      }

      {
        for (const auto apply_role_uuid : apply_role_uuid_list) {
          ApproveJoinGuildArg arg;
          arg.token = token_list[0];
          arg.apply_role_uuid = apply_role_uuid;
          rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
              std::shared_ptr<rpc::StubCallImpl>(nullptr));

          std::cout << "ApproveJoinGuild"
                    << "\t玩家凭证:" << arg.token
                    << "\t申请入会的角色唯一id:" << arg.apply_role_uuid << '\n';

          auto res = std::make_shared<ApproveJoinGuildRes>();
          try {
            guild_service::GuildServiceBasicContext::ApproveJoinGuild(call, arg, res);
            {
              std::cout << "ApproveJoinGuild"
                        << "\t结果:" << static_cast<int32_t>(res->result)
                        << '\n';
            }
            ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
          } catch (std::exception & ex) {
            std::cerr << "ApproveJoinGuild exception &:" << ex.what()
                      << std::endl;
          }
        }
      }) BOX_SERVICE_STOP(500)
}

/// 设置公会成员职位
CASE(TestGuildServiceBasic4){
  BOX_SERVICE_START()
  co(std::cout << '\n'; {
    SetGuildMemberDutyArg arg;
    arg.token = token_list[0];
    arg.member_role_uuid = role_uuid_list[1];
    arg.duty = guildservicebasic_cpp::GuildDuty::GUILD_DUTY_VICE_CHAIRMAN;
    rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
         std::shared_ptr<rpc::StubCallImpl>(nullptr));


    std::cout << "SetGuildMemberDuty"
              << "\t凭证:" << arg.token 
              << "\t成员角色唯一id:" << arg.member_role_uuid
              << "\t职责:" << static_cast<int>(arg.duty) << '\n';

    auto res = std::make_shared<SetGuildMemberDutyRes>();
    try {
      guild_service::GuildServiceBasicContext::SetGuildMemberDuty(call, arg, res);
      {
        std::cout << "SetGuildMemberDuty"
                  << "\t结果:" << static_cast<int32_t>(res->result) << '\n';
      }
      ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
    } catch (std::exception & ex) {
      std::cerr << "SetGuildMemberDuty exception &:" << ex.what() << std::endl;
    }
  }) BOX_SERVICE_STOP(500)
}

/// 获取公会成员信息
CASE(TestGuildServiceBasic5) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n'; {
        GetGuildMemberArg arg;
        arg.token = token_list[0];
        arg.member_uuid = role_uuid_list[1];
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "GetGuildMember"
                  << "\t凭证:" << arg.token
                  << "\t成员角色唯一id:" << arg.member_uuid << '\n';

        auto res = std::make_shared<GetGuildMemberRes>();
        try {
          guild_service::GuildServiceQueryContext::GetGuildMember(call, arg, res);
          {
            std::cout << "GetGuildMember"
                      << "\t结果:" << static_cast<int32_t>(res->result)
                      << "\t成员名字:" << res->member.name
                      << "\t成员角色唯一id:" << res->member.role_uuid
                      << "\t成员职责:" << static_cast<int>(res->member.duty)
                      << '\n';
          }
          ASSERT_TRUE(res->member.role_uuid == role_uuid_list[0]);
        } catch (std::exception & ex) {
          std::cerr << "GetGuildMember exception &:" << ex.what() << std::endl;
        }
      }

      {
        GetGuildMembersArg arg;
        arg.token = token_list[0];
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "GetGuildMembers"
                  << "\t角色唯一id:" << arg.token << '\n';

        auto res = std::make_shared<GetGuildMembersRes>();
        try {
          guild_service::GuildServiceQueryContext::GetGuildMembers(call, arg, res);
          {
            for (const auto& it : res->member_list.members) {
              std::cout << "GetGuildMembers"
                        << "\t结果:" << static_cast<int32_t>(res->result)
                        << "\t成员名字:" << it.name
                        << "\t成员角色唯一id:" << it.role_uuid
                        << "\t成员职责:" << static_cast<int>(it.duty)
                        << '\n';
            }
          }
          ASSERT_TRUE(res->result == guildservicequery_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception & ex) {
          std::cerr << "GetGuildMembers exception &:" << ex.what() << std::endl;
        }
      }) BOX_SERVICE_STOP(500)
}

/// 踢出公会成员
CASE(TestGuildServiceBasic6) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n'; KickOutGuildMemberArg arg; arg.token = token_list[0];
      arg.kick_role_uuid = role_uuid_list[3];
      rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
          std::shared_ptr<rpc::StubCallImpl>(nullptr));

      std::cout << "KickOutGuildMember"
                << "\t凭证:" << arg.token
                << "\t踢出的角色唯一id:" << arg.kick_role_uuid << '\n';

      auto res = std::make_shared<KickOutGuildMemberRes>(); try {
        guild_service::GuildServiceBasicContext::KickOutGuildMember(call, arg, res);
        {
          std::cout << "KickOutGuildMember"
                    << "\t结果:" << static_cast<int32_t>(res->result) << '\n';
        }
        ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
      } catch (std::exception& ex) {
        std::cerr << "KickOutGuildMember exception &:" << ex.what() << std::endl;
      }) BOX_SERVICE_STOP(500)
}

/// 搜索公会
CASE(TestGuildServiceBasic7) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n'; SearchGuildArg arg;

      arg.token = token_list[0]; arg.name = "guild" + std::to_string(arg.token);
      rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
          std::shared_ptr<rpc::StubCallImpl>(nullptr));

      std::cout << "SearchGuild"
                << "\t凭证:" << arg.token << "\t公会名字:" << arg.name << '\n';

      auto res = std::make_shared<SearchGuildRes>(); try {
        guild_service::GuildServiceQueryContext::SearchGuild(call, arg, res);
        {
          std::cout << "SearchGuild"
                    << "\t结果:" << static_cast<int32_t>(res->result)
                    << "\t公会名字:" << res->brief.name
                    << "\t会长角色唯一id:" << res->brief.chairman_uuid << '\n';
        }
        ASSERT_TRUE(res->result == guildservicequery_cpp::ErrorCode::ERR_SUCCESS);
      } catch (std::exception& ex) {
        std::cerr << "SearchGuild exception &:" << ex.what() << std::endl;
      }) BOX_SERVICE_STOP(500)
}

/// 获取公会列表
CASE(TestGuildServiceBasic8) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n'; GetGuildBriefListArg arg; arg.token = token_list[0];
      arg.count = 3;
      rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
          std::shared_ptr<rpc::StubCallImpl>(nullptr));

      std::cout << "GetGuildBriefList"
                << "\t凭证:" << arg.token << '\n';

      auto res = std::make_shared<GetGuildBriefListRes>(); try {
        guild_service::GuildServiceQueryContext::GetGuildBriefList(call, arg, res);
        {
          for (const auto& it : res->brief_list) {
            std::cout << "GetGuildBriefList"
                      << "\t结果:" << static_cast<int32_t>(res->result)
                      << "\t公会名字:" << it.name << "\t公会等级:" << it.level
                      << "\t会长角色唯一id:" << it.chairman_uuid << '\n';
          }
        }
        ASSERT_TRUE(res->result == guildservicequery_cpp::ErrorCode::ERR_SUCCESS);
      } catch (std::exception& ex) {
        std::cerr << "GetGuildBriefList exception &:" << ex.what() << std::endl;
      }) BOX_SERVICE_STOP(500)
}

/// 改变公会icon && 改变公会名字 && 改变公会宣言
CASE(TestGuildServiceBasic9) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n'; {
        ChangeGuildIconIdArg arg;
        arg.token = token_list[0];
        arg.icon_id = icon_id;
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "ChangeGuildIconId"
                  << "\t凭证:" << arg.token
                  << "\t图标id:" << arg.icon_id << '\n';

        auto res = std::make_shared<ChangeGuildIconIdRes>();

        try {
          guild_service::GuildServiceBasicContext::ChangeGuildIconId(call, arg, res);
          {
            std::cout << "ChangeGuildIconId"
                      << "\t结果:" << static_cast<int32_t>(res->result) << '\n';
          }
          ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception & ex) {
          std::cerr << "ChangeGuildIconId exception &:" << ex.what() << std::endl;
        }
      } {
        ChangeGuildNameArg arg;
        arg.token = token_list[0];
        arg.name = "new_guild" + std::to_string(token_list[0]);
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "ChangeGuildName"
                  << "\t凭证:" << arg.token
                  << "\t公会名字:" << arg.name << '\n';

        auto res = std::make_shared<ChangeGuildNameRes>();
        try {
          guild_service::GuildServiceBasicContext::ChangeGuildName(call, arg, res);
          {
            std::cout << "ChangeGuildName"
                      << "\t结果:" << static_cast<int32_t>(res->result) << '\n';
          }
          ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception & ex) {
          std::cerr << "ChangeGuildName exception &:" << ex.what() << std::endl;
        }
      } {
        ChangeGuildDeclarationArg arg;
        arg.token = token_list[0];
        arg.declaration = declaration;
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
            std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "ChangeGuildDeclaration"
                  << "\t凭证:" << arg.token
                  << "\t公会宣言:" << arg.declaration << '\n';

        auto res = std::make_shared<ChangeGuildDeclarationRes>();
        try {
          guild_service::GuildServiceBasicContext::ChangeGuildDeclaration(call, arg,
                                                                          res);
          {
            std::cout << "ChangeGuildDeclaration"
                      << " 结果:" << static_cast<int32_t>(res->result) << '\n';
          }
          ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception & ex) {
          std::cerr << "ChangeGuildDeclaration exception &:" << ex.what()
                    << std::endl;
        }
      } {
        ChangeGuildAnnounceArg arg;
        arg.token = token_list[0];
        arg.announce = announce;
        rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
         std::shared_ptr<rpc::StubCallImpl>(nullptr));

        std::cout << "ChangeGuildAnnounce"
                  << "\t角色唯一id:" << arg.token
                  << "\t公会通知:" << arg.announce << '\n';

        auto res = std::make_shared<ChangeGuildAnnounceRes>();
        try {
          guild_service::GuildServiceBasicContext::ChangeGuildAnnounce(call, arg,
                                                                       res);
          {
            std::cout << "ChangeGuildAnnounce"
                      << " 结果:" << static_cast<int32_t>(res->result) << '\n';
          }
          ASSERT_TRUE(res->result == guildservicebasic_cpp::ErrorCode::ERR_SUCCESS);
        } catch (std::exception & ex) {
          std::cerr << "ChangeGuildAnnounce exception &:" << ex.what()
                    << std::endl;
        }
      }) BOX_SERVICE_STOP(500)
}

/// 退出公会
CASE(TestGuildServiceBasic10) {
  BOX_SERVICE_START()
  co(
      std::cout << '\n'; QuitGuildArg arg; arg.token = token_list[0];
      rpc::StubCallPtr call = std::dynamic_pointer_cast<rpc::StubCall>(
         std::shared_ptr<rpc::StubCallImpl>(nullptr));

      std::cout << "QuitGuild"
                << "\t角色唯一id:" << arg.token << '\n';

      auto res = std::make_shared<QuitGuildRes>(); try {
        guild_service::GuildServiceBasicContext::QuitGuild(call, arg, res);
        {
          std::cout << "QuitGuild"
                    << "\t结果:" << static_cast<int32_t>(res->result) << '\n';
        }
        ASSERT_TRUE(res->result ==
                    guildservicebasic_cpp::ErrorCode::ERR_GUILD_MEMBERS_DUTY_CHAIRMAN);
      } catch (std::exception & ex) {
        std::cerr << "QuitGuild exception &:" << ex.what() << std::endl;
      }) BOX_SERVICE_STOP(500)
}

FIXTURE_END(test_guild_service_basic)
